package net.esj.basic.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.annotation.PostConstruct;

import org.springframework.core.io.Resource;

@Deprecated
public class Language {

	public static String ACTION_SAVE_SUCCESS;
	
	public static String ACTION_SAVE_ERROR;
	
	public static String ACTION_DELETE_SUCCESS;
	
	public static String ACTION_DELETE_ERROR;
	
	public static String ACTION_MODIFY_SUCCESS;
	
	public static String ACTION_MODIFY_ERROR;
	
	public static String ACTION_SUCCESS;
	
	public static String ACTION_ERROR;
	
	public static String SYSTEM_MESSAGE_TITLE;
	
	private static final Properties properties = new Properties();
	
	private Resource location;
	
	@PostConstruct
	public void load() throws IOException{
		InputStream is = null;
		try {
			is = location.getInputStream();
			properties.load(is);
			ACTION_SAVE_SUCCESS = properties.getProperty("action.save.success");
			ACTION_SAVE_ERROR = properties.getProperty("action.save.error");
			ACTION_DELETE_SUCCESS = properties.getProperty("action.delete.success");
			ACTION_DELETE_ERROR = properties.getProperty("action.delete.error");
			ACTION_MODIFY_SUCCESS = properties.getProperty("action.modify.success");
			ACTION_MODIFY_ERROR = properties.getProperty("action.modify.error");
			ACTION_SUCCESS = properties.getProperty("action.success");
			ACTION_ERROR = properties.getProperty("action.error");
			SYSTEM_MESSAGE_TITLE = properties.getProperty("system.message.title");
 		} catch (IOException ex) {
			throw ex;
		} finally {
			if (is != null) {
				is.close();
			}
		}
	}
	
	public static String getString(String key){
		return properties.getProperty(key);
	}
	
	public static String getString(String key,String def){
		return properties.getProperty(key,def);
	}
	
	public void setLocation(Resource location) {
		this.location = location;
	}
	
}
